<template>
  <el-dialog
    :title="!this.dataForm.scId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm"  label-width="80px">
    <el-form-item label="商品名称" prop="scSpName">
      <el-input disabled v-model="dataForm.scSpName" placeholder="商品昵称"></el-input>
    </el-form-item>
    <el-form-item label="商品" prop="scSpId">
      <el-input v-model="dataForm.scSpId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="用户" prop="scUrId">
      <el-input v-model="dataForm.scUrId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="总数" prop="scCount">
          <el-input-number disabled v-model="dataForm.scCount" :min="1"></el-input-number>
      <!-- <el-input v-model="dataForm.scCount" placeholder=""></el-input> -->
    </el-form-item>
    <el-form-item label="商品加购的总价格" prop="scPriceCount">
      <el-input disabled v-model="dataForm.scPriceCount" placeholder="商品加购的总价格"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import api from "@/api/modules/cbbshoppingcart";
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          scId: 0,
          scSpName: '',
          scSpId: '',
          scUrId: '',
          scCount: '',
          scPriceCount: ''
        },
        dataRule: {
          scSpName: [
            { required: true, message: '商品昵称不能为空', trigger: 'blur' }
          ],
          scSpId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          scUrId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          scCount: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          scPriceCount: [
            { required: true, message: '商品加购的总价格不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.scId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          api.info(this.dataForm.scId).then(({data}) => {
              if (data) {
                this.dataForm.scSpName = data.cbbShoppingCart.scSpName
                this.dataForm.scSpId = data.cbbShoppingCart.scSpId
                this.dataForm.scUrId = data.cbbShoppingCart.scUrId
                this.dataForm.scCount = data.cbbShoppingCart.scCount
                this.dataForm.scPriceCount = data.cbbShoppingCart.scPriceCount
              }
            })
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
    var parms= {
'scId': this.dataForm.scId || undefined,
'scSpName': this.dataForm.scSpName,
'scSpId': this.dataForm.scSpId,
'scUrId': this.dataForm.scUrId,
'scCount': this.dataForm.scCount,
'scPriceCount': this.dataForm.scPriceCount        }
        api.updateAdd(parms,this.dataForm.scId).then((res) => {
              if (res.code==200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
